package edu.gatech.foodaway;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Toast;

public class AddItemActivity extends Activity {
	TextView txt_rname;
	ImageView img_rpicture;
	TextView txt_sname;
	TextView txt_sftype;
	Button btn_add;
	Spinner foodtype;
	ImageView img_fpicture;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_additem);
		txt_rname = (TextView) findViewById(R.id.textView_additem_restaurantname);
		img_rpicture = (ImageView)findViewById(R.id.imageView_additem_restaurantpic);
		foodtype = (Spinner) findViewById(R.id.spinner1);
		btn_add = (Button) findViewById(R.id.btn_additem_additem);
		img_fpicture = (ImageView) findViewById(R.id.imageView_foodpicture);
		
		addListenerOnButton();
		addListenerOnSpinnerItemSelection();		
		}
	
	public void addListenerOnSpinnerItemSelection() {
		foodtype = (Spinner) findViewById(R.id.spinner1);
		foodtype.setOnItemSelectedListener(new CustomOnItemSelectedListener());
	  }
	
	public class CustomOnItemSelectedListener implements OnItemSelectedListener {
		 
		  public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
			Toast.makeText(parent.getContext(), 
				"OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
				Toast.LENGTH_SHORT).show();
		  }
		 
		  @Override
		  public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
		  }
		 
		}
	
	public void addListenerOnButton() {
		 
		foodtype = (Spinner) findViewById(R.id.spinner1);
		btn_add = (Button) findViewById(R.id.btn_additem_additem);
	 
		btn_add.setOnClickListener(new OnClickListener() {
	 
		  @Override
		  public void onClick(View v) {
	 
		    Toast.makeText(AddItemActivity.this,
			"OnClickListener : " + 
	                "\nSpinner 1 : "+ String.valueOf(foodtype.getSelectedItem()),
				Toast.LENGTH_SHORT).show();
		  }
	 
		});
	  }
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.donorhome, menu);
		return true;
	}


}
